#pragma once
#include <string>
#include <iostream>
#include <cstddef>
#include <odb/core.hxx>
#include <odb/nullable.hxx>
#include <boost/date_time/posix_time/posix_time.hpp>


#pragma db object table("message")
class Message
{
    public:
    Message() {}

    Message(const std::string& mid,
    const std::string& ssid,
    const std::string& uid,
    const unsigned char message_type,
    const boost::posix_time::ptime create_time) :_message_id(mid)
    ,_session_id(ssid)
    ,_user_id(uid)
    ,_message_type(message_type),_create_time(create_time){}

    std::string message_id() const {return _message_id;}
    void set_message_id(const std::string& message_id) { _message_id = message_id; }

    std::string session_id() const { return _session_id; }
    void set_session_id(const std::string& session_id) { _session_id = session_id; }

    std::string user_id() const {return _user_id; }
    void set_user_id(const std::string& user_id) {_user_id = user_id; } 

    unsigned char message_type() const {return _message_type; }
    void set_message_type(unsigned char message_type) { _message_type = message_type; }

    boost::posix_time::ptime create_time() const {return _create_time;}
    void set_create_time(const boost::posix_time::ptime& create_time) { _create_time = create_time; }

    std::string content() const {
        if(!_content) {
            return std::string();
        }
        return *_content;
    }
    void set_content(const std::string& content) { _content = content; }

    std::string file_id() const {
        if(!_file_id) {
            return std::string();
        }

        return *_file_id;
    }
    void set_file_id(const std::string& file_id) {_file_id = file_id; }

    std::string file_name() const {
        if(!_file_name) {
            return std::string();
        }

        return *_file_name;
    }
    void set_file_name(const std::string& file_name) {_file_name = file_name; }

    unsigned int file_size() const {
        if(!_file_size) {
            return 0;
        }

        return *_file_size;
    }
    void set_file_size(const unsigned int& file_size) {_file_size = file_size; }

    private:
        friend class odb::access;
        #pragma db id auto
        unsigned long _id;
        #pragma db type ("varchar(64)") index unique 
        std::string _message_id;
        #pragma db type ("varchar(64)") index 
        std::string _session_id;            //所属ID
        #pragma db type ("varchar(64)")  
        std::string _user_id;
        unsigned char _message_type;
        #pragma db type("TIMESTAMP")
        boost::posix_time::ptime _create_time;    //消息的产生时间
        
        odb::nullable<std::string> _content;        //消息内容
        #pragma db type("varchar(64)")
        odb::nullable<std::string> _file_id;        //文件ID
        #pragma db type("varchar(128)")
        odb::nullable<std::string> _file_name;      //文件名字
        odb::nullable<unsigned int> _file_size;     //文大小
};

//odb -d mysql --generate-query --generate-schema --profile boost/date-time person.hxx